<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将 WebP 格式的图像输出到浏览器或文件</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imagewebp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagewebp</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7)</p><p class="refpurpose"><span class="refname">imagewebp</span> &mdash; <span class="dc-title">将 WebP 格式的图像输出到浏览器或文件</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.imagewebp-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagewebp</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$to</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$quality</code><span class="initializer"> = 80</span></span>
  ]] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   将 <code class="parameter">image</code> 参数指定的图像以 WebP 格式输出到浏览器或者保存到文件。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.imagewebp-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    <dt>
<code class="parameter">image</code></dt>

<dd>
<p class="para">由图象创建函数(例如<span class="function"><a href="imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>)返回的图象资源。</p></dd>

    
     <dt>
<code class="parameter">to</code></dt>

     <dd>

      <p class="para">文件保存的路径，如果未设置或为 <strong><code>NULL</code></strong>，将会直接输出原始图象流。</p>
     </dd>

    
    
     <dt>
<code class="parameter">quality</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">quality</code> 范围从0（最低质量，最小文件体积）到100 （最好质量, 最大文件体积）。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.imagewebp-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.imagewebp-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.4.0</td>
       <td>
        支持把 <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span> 流作为
        <code class="parameter">to</code> 参数传入。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.imagewebp-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3745">
    <p><strong>Example #1 保存为 WebP 图像文件</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;创建一个空图像并在其上加入一些文字<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">120</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$text_color&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">233</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">14</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">91</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">imagestring</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #DD0000">'WebP&nbsp;with&nbsp;PHP'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text_color</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;保存图像<br /></span><span style="color: #0000BB">imagewebp</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'php.webp'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;释放内存<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

</div></div></div></body></html>